package hdd.config;

import org.aspectj.apache.bcel.util.ClassPath;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.remoting.rmi.RmiServiceExporter;
import service.TestService;

@Configuration
@PropertySource( {"classpath:setting.properties"} )
public class RmiBeanConfig   implements EnvironmentAware {
    private Environment environment;

    @Bean
    public RmiServiceExporter testService(TestService testService){
        RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
        rmiServiceExporter.setService( testService );
        rmiServiceExporter.setServiceInterface(TestService.class );
        rmiServiceExporter.setServiceName( TestService.class.getSimpleName() );
        rmiServiceExporter.setRegistryPort( environment.getProperty( "rmi.registryPort",Integer.class ) );
        rmiServiceExporter.setServicePort( environment.getProperty( "rmi.servicePort",Integer.class ) );
        return rmiServiceExporter;
    }
    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }
}
